from interface.MemberInterface import MemberInterface
from interface.ShopInterface import ShopInterface
from utils.GetKeyword import GetKeyword
from utils.SendMethod import SendMethod


class OrderInterface:
    def __init__(self, url):
        self.url = url
        self.headers = MemberInterface(url).get_token("KFC7516", "654321")

    # 确认订单
    def confirm_order(self, cart_ids):
        url = self.url + "/order/generateConfirmOrder"
        body = [cart_ids]
        return SendMethod.send_method(method='post', url=url, json=body, headers=self.headers)

    # 生成订单
    def generate_order(self, order_params):
        url = self.url + "/order/generateOrder"
        return SendMethod.send_method(method='post', url=url, json=order_params, headers=self.headers)

    def pay_success(self, orderid):
        url = self.url + "/order/paySuccess"
        return SendMethod.send_method(method='post', url=url, data=orderid, headers=self.headers)


if __name__ == '__main__':
    url = "http://47.108.206.100:8085"
    oi = OrderInterface(url)
    cart_info = {
        "cartIds": [
            3323
        ],
        "memberReceiveAddressId": 2546,
        "payType": 1
    }
    orderid = {
        "orderId": 4193,
        "payType": 1
    }
    # print(oi.confirm_order(3323))
    # print(oi.generate_order(cart_info))
    print(oi.pay_success(orderid))
